home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / perl / perl5a1.lha / perl5alpha1 / do / slice < prev    next >
Encoding:
Text File  |  1992-08-15  |  1.9 KB  |  97 lines

  1. int
  2. do_slice(stab,TARG,numarray,lval,gimme,arglast)
  3. STAB *stab;
  4. STR *TARG;
  5. int numarray;
  6. int lval;
  7. int gimme;
  8. int *arglast;
  9. {
  10.     register STR **st = stack->ary_array;
  11.     register int sp = arglast[1];
  12.     register int max = arglast[2];
  13.     register char *tmps;
  14.     register int len;
  15.     register int magic = 0;
  16.     register ARRAY *ary;
  17.     register HASH *hash;
  18.     int oldarybase = arybase;
  19.  
  20.     if (numarray) {
  21.     if (numarray == 2) {        /* a slice of a LIST */
  22.         ary = stack;
  23.         ary->ary_fill = arglast[3];
  24.         arybase -= max + 1;
  25.         st[sp] = TARG;        /* make stack size available */
  26.         str_numset(TARG,(double)(sp - 1));
  27.     }
  28.     else
  29.         ary = stab_array(stab);    /* a slice of an array */
  30.     }
  31.     else {
  32.     if (lval) {
  33.         if (stab == envstab)
  34.         magic = 'E';
  35.         else if (stab == sigstab)
  36.         magic = 'S';
  37. #ifdef SOME_DBM
  38.         else if (stab_hash(stab)->tbl_dbm)
  39.         magic = 'D';
  40. #endif /* SOME_DBM */
  41.     }
  42.     hash = stab_hash(stab);        /* a slice of an associative array */
  43.     }
  44.  
  45.     if (gimme == G_ARRAY) {
  46.     if (numarray) {
  47.         while (sp < max) {
  48.         if (st[++sp]) {
  49.             st[sp-1] = afetch(ary,
  50.               ((int)str_gnum(st[sp])) - arybase, lval);
  51.         }
  52.         else
  53.             st[sp-1] = &str_undef;
  54.         }
  55.     }
  56.     else {
  57.         while (sp < max) {
  58.         if (st[++sp]) {
  59.             tmps = str_get(st[sp]);
  60.             len = st[sp]->str_cur;
  61.             st[sp-1] = hfetch(hash,tmps,len, lval);
  62.             if (magic)
  63.             str_magic(st[sp-1],stab,magic,tmps,len);
  64.         }
  65.         else
  66.             st[sp-1] = &str_undef;
  67.         }
  68.     }
  69.     sp--;
  70.     }
  71.     else {
  72.     if (sp == max)
  73.         st[sp] = &str_undef;
  74.     else if (numarray) {
  75.         if (st[max])
  76.         st[sp] = afetch(ary,
  77.           ((int)str_gnum(st[max])) - arybase, lval);
  78.         else
  79.         st[sp] = &str_undef;
  80.     }
  81.     else {
  82.         if (st[max]) {
  83.         tmps = str_get(st[max]);
  84.         len = st[max]->str_cur;
  85.         st[sp] = hfetch(hash,tmps,len, lval);
  86.         if (magic)
  87.             str_magic(st[sp],stab,magic,tmps,len);
  88.         }
  89.         else
  90.         st[sp] = &str_undef;
  91.     }
  92.     }
  93.     arybase = oldarybase;
  94.     return sp;
  95. }
  96.  
  97.